package com.tedu.controller;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.tedu.dao.DoorMapper;
import com.tedu.pojo.Door;

/** 测试mybatis运行环境 */
public class TestMybatis {
	
	/** 查询所有门店信息 
	 * @throws IOException */
	public static void main(String[] args) throws IOException {
		//读取mybatis-config.xml配置文件
		InputStream in = Resources
				.getResourceAsStream("mybatis/mybatis-config.xml");
		//获取SqlSessionFactory工厂对象
		SqlSessionFactory fac = 
				new SqlSessionFactoryBuilder().build( in );
		//获取SqlSession对象
		SqlSession session = fac.openSession();
		//获取mapper接口的实现类的实例
		DoorMapper dao = session.getMapper( DoorMapper.class );
		//执行查询所有门店的方法
		List<Door> list = dao.findAll();
		//输出结果
		for (Door door : list) {
			System.out.println( door );
		}
	}
}


